package com.aaa.controller;

import com.aaa.entity.Comment;
import com.aaa.service.CommentService;
import com.aaa.util.DefaultMsg;
import com.aaa.util.TableData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @RequestMapping("/toList")
    public String toList(){
        return "comment/list";
    }

    @RequestMapping("/listData")
    @ResponseBody
    public TableData<Comment> listData(@RequestParam(defaultValue = "")String keyword, Integer page, Integer limit){
        TableData<Comment> page1 = commentService.page(keyword, page, limit);
        return page1;
    }

    @RequestMapping("/saveOrupdate")
    @ResponseBody
    public DefaultMsg saveOrupdate(Comment comment){
        DefaultMsg defaultMsg = commentService.saveOrupdate(comment);
        return defaultMsg;
    }

    @RequestMapping("/toEdit")
    public String toEdit(){
        return "comment/edit";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public DefaultMsg delete(Integer id){
        DefaultMsg delete = commentService.delete(id);
        return delete;
    }
}
